package auth

import (
	"github.com/iris-contrib/middleware/jwt"
	"iris-demo/core"
	"time"
)

type User struct {
	core.Model
	Username string `gorm:"not null;unique;size:255" json:"username"`
	Password string `gorm:"not null;size:255" json:"password,omitempty" `
}

func (u User) CreateJwtToken() (string, error) {
	token := jwt.NewTokenWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
		"id":         u.ID,
		"username":   u.Username,
		"exp":        time.Now().Add(time.Hour * 1).Unix(),
		"token_type": "access",
	})
	return token.SignedString([]byte(core.Config.App.SecretKey))
}
